package com.xinzhi.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.xinzhi.model.User;

import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegUtils {


    private RegUtils(){

    }

    public static boolean check(String target,String regex) {
        // 要匹配的手机号码
//        String phoneNumber = "1234567890"; // 替换成你要匹配的手机号

        // 定义手机号正则表达式
//        String regex = "^(1[3-9]\\d{9})$";

        // 编译正则表达式
        Pattern pattern = Pattern.compile(regex);

        // 创建匹配器
        Matcher matcher = pattern.matcher(target);

        // 进行匹配
        if (matcher.matches()) {
            return true;
        }
        return false;
    }


    public static void main(String[] args) {
        User tom = User.builder().id(1).username("tom").build();
        User lili = User.builder().id(2).username("lili").build();
        String str = JSON.toJSONString(tom);
        System.out.println(str);

        String s = "{\"age\":0,\"id\":1,\"username\":\"tom\"}";
        User user = JSON.parseObject(s, User.class);
        System.out.println(user);


        List<User> list = Arrays.asList(tom, lili);
        String jList = JSONArray.toJSONString(list);
        System.out.println(jList);

        String jList1 = "[{\"age\":0,\"id\":1,\"username\":\"tom\"},{\"age\":0,\"id\":2,\"username\":\"lili\"}]";
        List<User> users = JSONArray.parseArray(jList1, User.class);
        System.out.println(users);
    }
}



